//
//  XMApplyForReturnViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/20.
//

#import "XMApplyForReturnViewController.h"
#import "XMApplyForReturnView.h"
#import "XMNetwork+mine.h"

@interface XMApplyForReturnViewController ()

@property (nonatomic, strong) XMApplyForReturnView *returnView;

@end

@implementation XMApplyForReturnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.returnView];
    [self getRuleInfo];
    [_returnView setContentWithMeetDetailModel:_orderDetailModel];
    XMWeakSelf;
    _returnView.applyForBlock = ^(NSString * _Nonnull reasonMy, NSString * _Nonnull reasonOther, NSString * _Nonnull reasonExplainStr) {
        [weakSelf applyForReturnWithReasonMy:reasonMy
                                 reasonOther:reasonOther
                               reasonExplain:reasonExplainStr];
    };
}

//退款规则
- (void)getRuleInfo {
    XMWeakSelf;
    [_Network getReturnRuleSuccess:^(id  _Nonnull responseObject) {
        [weakSelf.returnView setContentWithRuleArr:[responseObject[@"data"] safeStringForKey:@"content"]];
    } failure:^(NSError * _Nonnull error) {
        
    }];}

//申请退款
- (void)applyForReturnWithReasonMy:(NSString *)reasonMy
                       reasonOther:(NSString *)reasonOther
                     reasonExplain:(NSString *)reasonExplainStr {
    XMWeakSelf;
    [_Network applyForReturnWithOrderId:_orderDetailModel.orderId
                               reasonMy:reasonMy
                            reasonOther:reasonOther
                          reasonExplain:reasonExplainStr
                                success:^(id _Nonnull responseObject) {
        [MBProgressHUD showSuccess:@"申请成功"];
        weakSelf.editSuccessBlock ? weakSelf.editSuccessBlock() : nil;
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

- (XMApplyForReturnView *)returnView {
    if (!_returnView) {
        _returnView = [[XMApplyForReturnView alloc] initWithFrame:self.view.bounds];
    }
    return _returnView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
